import 'package:redux/redux.dart';
// ps使用redux尤其注意泛型

enum StoreActionType { UserLogin, userLogout }

class StoreState {
  String nickname;
  StoreState({this.nickname});
}

class StoreAction {
  final StoreActionType type;
  final dynamic arguments;
  StoreAction(this.type, [this.arguments]);
}

StoreState _reducer(StoreState state, _action) {
  StoreAction action = _action;
  switch (action.type) {
    case StoreActionType.UserLogin:
      state.nickname = action.arguments as String;
      break;
    case StoreActionType.userLogout:
      state.nickname = null;
      break;

    default:
      throw Error();
  }

  return state;
}

createStore() {
  return Store<StoreState>(_reducer, initialState: StoreState());
}
